package m202405.d14;

import java.util.Map;

/**
 * @@author: 爱做梦的锤子
 * @date: 2024/5/14 15:25
 */
public class Q153 {

    public static void main(String[] args) {
        Q153 q153 = new Q153();
        int min = q153.findMin(new int[]{4, 5, 1, 2, 3});
        System.out.println();
    }

    public int findMin(int[] nums) {
        return find(nums, 0, nums.length);
    }

    private int find(int[] nums, int start, int end) {
        if (end - start <= 3) {
            return min(nums, start, end);
        }
        int mid = (start + end) / 2;
        if (nums[start] > nums[mid - 1]) {
            return find(nums, start, mid);
        }
        if (nums[mid] > nums[end - 1]) {
            return find(nums, mid, end);
        }
        return Math.min(nums[0], nums[mid]);
    }

    private int min(int[] nums, int start, int end) {
        int min = nums[start];
        for (int i = start; i < end; i++) {
            min = Math.min(min, nums[i]);
        }
        return min;
    }
}
